﻿#if NETCOREAPP3_0
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Microsoft.Extensions.DependencyInjection
{
    /// <summary>
    /// System.Text.Json 扩展操作类
    /// </summary>
    public static class JsonExtensions
    {
        /// <summary>
        /// 提供默认配置 支持驼峰命名方法（Pascal）
        /// </summary>
        /// <param name="options">JsonSerializerOptions 实例</param>
        /// <remarks>内部 Converters 增加了时间转化器</remarks>
        /// <returns></returns>
        public static JsonSerializerOptions AddDefaultConverters(this JsonSerializerOptions options)
        {
            options.PropertyNamingPolicy = null;
            options.PropertyNameCaseInsensitive = true;
            options.Converters.Add(new JsonStringEnumConverter());
            options.Converters.Add(new StringToNumberConverter());
            options.Converters.Add(new StringToTimeSpanConverter());
            options.Converters.Add(new CustomerDateTimeConverter());
            options.Converters.Add(new CustomerDateTimeOffsetConverter());
            return options;
        }
    }
}
#endif
